<template>
  <el-card class="page-container">
    <template #header>
      <div class="header">
        <span>完善家长信息</span>
      </div>
    </template>
    <el-form :model="patriarchInfo" :rules="rules" ref="patriarchForm" label-width="100px">
      <el-form-item label="家长姓名" prop="patriarchName">
        <el-input v-model="patriarchInfo.patriarchName" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm">保存</el-button>
        <el-button @click="resetForm">重置</el-button>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script setup>
import { ref } from 'vue';
import { ElMessage } from 'element-plus';
import { improvePatriarchInfo } from '@/api/patriarchtImprove.js';
import { useRouter } from 'vue-router';

const router = useRouter();

const patriarchInfo = ref({
  patriarchName: '',
});

const rules = {
  patriarchName: [{ required: true, message: '请输入家长姓名', trigger: 'blur' }],
};

const resetForm = () => {
  patriarchInfo.value = {
    patriarchName: '',
  };
};

const submitForm = async () => {
  try {
    const result = await improvePatriarchInfo(patriarchInfo.value);
    if (result.code === 0) {
      ElMessage.success(result.msg || '保存成功');
      router.push('/');
    } else {
      ElMessage.error(result.msg || '保存失败');
    }
  } catch (error) {
    ElMessage.error('请求失败，请重试');
  }
};
</script>

<style scoped>
.page-container {
  max-width: 500px;
  margin: 20px auto;
}

.header {
  font-size: 18px;
  font-weight: bold;
  margin-bottom: 20px;
}
</style>
